package com.cn.kabalifeuser.ui.service.activity;

import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.base.IBaseActivity;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.service.bean.CaseDetailsBean;
import com.cn.kabalifeuser.ui.service.bean.CaseListBean;
import com.cn.kabalifeuser.utils.GlideUtil;
import com.cn.kabalifeuser.utils.RxToast;
import com.makeramen.roundedimageview.RoundedImageView;
import com.zzhoujay.richtext.ImageHolder;
import com.zzhoujay.richtext.RichText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 晓林 on 2020/9/11.
 * function: 服务案例详情
 */
public class ServiceCaseDetailsActivity extends IBaseActivity<ServiceCaseListView, ServiceCaseListPresenter> implements ServiceCaseListView {


    Bundle bundle;
    int id;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.img_cover)
    RoundedImageView imgCover;
    @BindView(R.id.tv_details)
    TextView tvDetails;


    @Override
    protected ServiceCaseListPresenter createPresenter() {
        return new ServiceCaseListPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_service_case_details;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        setTitleBar("案例详情");
        bundle = getIntent().getExtras();
        id = bundle.getInt("id");

        mPresenter.onCaseDetailsData(LoginHelper.getLonginData().getResult(), id);

    }

    @Override
    public void onReLoggedIn(String msg) {
        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return null;
    }

    @Override
    public void onCaseListSuccess(CaseListBean bean) {

    }

    @Override
    public void onCaseDetailsSuccess(CaseDetailsBean bean) {
//        tvTitle.setText(bean.getResult().getTitle());
//        GlideUtil.ImageLoad(this, bean.getResult().getCover(), imgCover);
//        RichText.fromHtml(bean.getResult().getContent()).into(tvDetails);
        RichText.fromHtml(bean.getResult().getContent()).autoFix(true).showBorder(false).autoPlay(true).scaleType(ImageHolder.ScaleType.center_crop) // 图片缩放方式
                .size(ImageHolder.MATCH_PARENT, ImageHolder.WRAP_CONTENT).into(tvDetails);
    }

    @OnClick(R.id.tv_btn_next)
    public void onViewClicked() {
        bundle = new Bundle();
        bundle.putInt("id", id);
        $startActivity(ServiceAddActivity.class, bundle);
    }


}
